package fr.ece.ing4.si.gui;

import javax.swing.*;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class Graph {
	
	private JPanel panel;
	private XYSeries data;
	private XYSeriesCollection dataset;
	private JFreeChart graph;
	
	
	/* Overloaded constructor */
	
	public Graph(JPanel panel, String graphName, String curveName, String xAxis, String yAxis) {
		
		this.panel = panel;
		this.data = new XYSeries(curveName);
		this.dataset = new XYSeriesCollection(this.data);
		this.graph = ChartFactory.createXYLineChart(graphName, xAxis, yAxis, dataset, PlotOrientation.VERTICAL, true, false, false);
		
		ChartPanel chartPanel = new ChartPanel(graph);
		
		this.panel.add(chartPanel);
		
		chartPanel.setOpaque(false);
		this.panel.setOpaque(false);
		graph.setBackgroundPaint(null);
		
	}
	
	
	public void refreshGraph(double x, double y) {
		
		data.add(x, y);
		
	}
	
}
